package com.osdp.sc.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.osdp.sc.entity.ScRoleUser;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface ScRoleUserMapper extends BaseMapper<ScRoleUser> {

    @Select("select role_code from sc_role where id in ( " +
            "select role_id from sc_role_user ur where ur.user_id= " +
            "(SELECT id FROM uc_user WHERE username = #{username})) " +
            "UNION ALL "+
            "SELECT up.position_id FROM uc_user u INNER JOIN sc_role_position up ON u.id = up.user_id " +
            "WHERE u.username =#{username}")
    List<String> getRoleByUserName(@Param("username") String username);

    @Select("select ur.id,u.username, up.org_id, d.org_name " +
            "from sc_role_user ur "+
            "left join uc_user u on ur.user_id = u.id " +
            "left join sc_role_position up on ur.user_id = up.user_id " +
            "left join uc_organization d on up.org_id = d.id " +
            "where ur.role_id = #{roleId}")
    List<Map<String, String>> getUserIdByRoleId(@Param("roleId") String roleId);
}
